package alg20250213;

public class Text2 {
    public int lengthOfLongestSubstring(String ss) {
        int n = ss.length();
        char[] s = ss.toCharArray();
        int[] hash = new int[128];
        int len = 0;
        for (int left = 0, right = 0; right < n; right++) {
            //进窗口
            hash[s[right]]++;
            //判断
            while(hash[s[right]] == 2){
                //出窗口
                hash[s[left++]]--;
            }
            //更新结果
            len = Math.max(len, right - left + 1);
        }
        return len;
    }
}
